package cn.controller;

import cn.entity.AppVersion;
import cn.entity.Result;
import cn.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@RestController
@RequestMapping("/app")
public class AppVersionController {

    @Autowired
    AppVersionService appVersionService;

    @RequestMapping("/select/{pageNum}/{pageSize}")
    public Result select(@PathVariable("pageNum")int pageNum,@PathVariable("pageSize")int pageSize){
        return new Result(true,"成功",appVersionService.selectPage(pageNum,pageSize));
    }

    @RequestMapping("index")
    public ModelAndView index(){
        return new ModelAndView("app/index");
    }

    @RequestMapping("upDateView")
    public ModelAndView upDateView(){
        return new ModelAndView("/app/update");
    }

    @RequestMapping("/selectOne/{id}")
    public Result selectOne(@PathVariable int id){
        return new Result(true,"",appVersionService.selectByPrimaryKey(id));
    }

    @RequestMapping("/doUpdate")
    public Result  doUpdate(@RequestBody AppVersion appVersion){
        appVersion.setUpdateDate(new Date());
        return new Result(true,"更新成功",appVersionService.updateByPrimaryKeySelective(appVersion));
    }

    @RequestMapping("/deleteOne/{id}")
    public int deleteOne(@PathVariable int id){
        AppVersion appVersion = appVersionService.selectByPrimaryKey(id);
        appVersion.setDelFlag("1");
        appVersion.setUpdateDate(new Date());
        return appVersionService.updateByPrimaryKeySelective(appVersion);
    }
    @RequestMapping("/insertOne")
    public int insertOne(@RequestBody AppVersion appVersion){
        appVersion.setCreateDate(new Date());
        appVersion.setDelFlag("0");
        appVersion.setUpdateDate(new Date());
        return appVersionService.insertSelective(appVersion);
    }

    @RequestMapping("detailHtml")
    public ModelAndView detailHtml(){
        return new ModelAndView("/app/detail");
    }

    @RequestMapping("detailView")
    public Result detailView(int id){
        return new Result(true,"查询成功",appVersionService.selectByPrimaryKey(id));
    }

}
